home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / prog / itsy.zip / ITSYTEST.C < prev    next >
C/C++ Source or Header  |  1993-03-19  |  16KB  |  510 lines

  1. ////////////////////////////////////////////////////////////////////////
  2. //
  3. //     Project:  ItsyBits Test Application
  4. //
  5. //      Module:  ITSYTEST.C
  6. //
  7. //   Revisions:  
  8. //      8/13/92     cek     Wrote it.
  9. //      2/24/93     cek     Updated to support min/max buttons.
  10. //                          Added more test cases.
  11. //
  12. ////////////////////////////////////////////////////////////////////////
  13.  
  14. #include "PRECOMP.H"
  15. #include "version.h"
  16. #include "ITSYTEST.h"
  17.  
  18.  
  19. #include "itsybits.h"
  20.  
  21. // Global variables extern'd in ITSYTEST.h
  22. //
  23. HWND          hwndApp ;
  24. HINSTANCE     hinstApp ;
  25.  
  26. // Variables local to this module.
  27. //
  28. static HCURSOR      hcurWait ;
  29. static HCURSOR      hcurNorm ;
  30. static HCURSOR      hcurSave ;
  31. static UINT         fWaitCursor ;
  32.  
  33. // In this sample, we have a bunch of itsybits windows we create.
  34. // We store their window handles in these static HWNDs.
  35. //
  36. static HWND hwnd1 ;
  37. static HWND hwnd2 ;
  38. static HWND hwnd3 ;
  39. static HWND hwnd4 ;
  40. static HWND hwnd5 ;
  41. static HWND hwnd6 ;
  42.  
  43.  
  44.  
  45. // Function Prototypes
  46. //
  47. BOOL WINAPI InitClass( HINSTANCE hInstance ) ;
  48. HWND WINAPI CreateMain( VOID ) ;
  49. BOOL WINAPI DoAboutBox( VOID ) ;
  50.  
  51. ////////////////////////////////////////////////////////////////
  52.  
  53. //  LRESULT CALLBACK fnItsyWnd( HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
  54. //
  55. //  Window proc for sample ItsyBits windows.  We trap the L and R
  56. //  mouse buttons and increase or decrease the size of the caption
  57. //  on each click.
  58. //
  59. ////////////////////////////////////////////////////////////////
  60. LRESULT CALLBACK fnItsyWnd( HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
  61. {
  62.     switch( uiMsg )
  63.     {
  64.         case WM_LBUTTONDBLCLK:
  65.             if (wParam & MK_SHIFT)
  66.                 ibSetCaptionSize( hWnd, ibGetCaptionSize( hWnd ) - 1 ) ;
  67.             else
  68.                 ibSetCaptionSize( hWnd, ibGetCaptionSize( hWnd ) + 1 ) ;
  69.         break ;
  70.  
  71.         case WM_RBUTTONDBLCLK:
  72.         {
  73.             DWORD dw = GetWindowLong( hWnd, GWL_STYLE ) ;
  74.             RECT rc ;
  75.  
  76.             if (dw & IBS_HORZCAPTION)
  77.             {
  78.                 dw &= ~IBS_HORZCAPTION ;
  79.                 dw |= IBS_VERTCAPTION ;
  80.             }
  81.             else
  82.             {
  83.                 dw &= ~IBS_VERTCAPTION ;
  84.                 dw |= IBS_HORZCAPTION ;
  85.             }
  86.             SetWindowLong( hWnd, GWL_STYLE, (LONG)dw ) ;
  87.  
  88.             GetWindowRect( hWnd, &rc ) ;
  89.         
  90.             // Once we change the window style, we need a WM_NCCALCRECT
  91.             // to be generated.
  92.             //
  93.             // SWP_FRAMECHANGED is not documented in the 3.1 SDK docs,
  94.             // but *is* in WINDOWS.H.
  95.             //
  96.             SetWindowPos( hWnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | 
  97.                                 SWP_NOSIZE | SWP_NOMOVE | 
  98.                                 SWP_NOACTIVATE | SWP_NOZORDER) ;
  99.  
  100.         }    
  101.         break ;
  102.  
  103.         case WM_PAINT:
  104.         {
  105.             PAINTSTRUCT ps ;
  106.             HFONT       hfont ;
  107.             RECT        rc ;
  108.             char        sz[] = "Left DblClk (+)\n\n"\
  109.                                "Shift Left DblClk (-)\n\n"\
  110.                                "Right DblClk swaps" ;
  111.  
  112.             BeginPaint( hWnd, &ps ) ;
  113.             GetClientRect( hWnd, &rc ) ;
  114.             InflateRect( &rc, -3, -3 ) ;
  115.  
  116.             hfont = CreateFont( -8, 0, 0, 0, 0, 0, 
  117.                                 0, 0, ANSI_CHARSET, 0, 0, 0,
  118.                                 FF_SWISS, "MS Sans Serif" ) ;
  119.             hfont = SelectObject( ps.hdc, hfont ) ;
  120.  
  121.             DrawText( ps.hdc, sz, lstrlen(sz), &rc, DT_NOPREFIX | DT_WORDBREAK ) ;
  122.  
  123.             hfont = SelectObject( ps.hdc, hfont ) ;
  124.             DeleteObject( hfont ) ;
  125.  
  126.             EndPaint( hWnd, &ps ) ;
  127.         }
  128.         break ;
  129.  
  130.         default:
  131.             return ibDefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
  132.     }
  133.  
  134.     return 0L ;
  135.  
  136. } // fnItsyWnd() 
  137.  
  138. ////////////////////////////////////////////////////////////////
  139. //  LRESULT FAR PASCAL
  140. //     fnMainWnd( HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
  141. //
  142. //     Main Window procedure.
  143. //
  144. ////////////////////////////////////////////////////////////////
  145. LRESULT CALLBACK fnMainWnd( HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
  146. {
  147.     switch( uiMsg )
  148.     {
  149.         case WM_CREATE:
  150.         {
  151.             UINT      cx, cy, dx, dy ;
  152.  
  153.             hwndApp = hWnd ;
  154.  
  155.             #define CX 25 
  156.             #define CY 50 
  157.             #define DX 125 
  158.             #define DY 175
  159.  
  160.             cx = CX ;
  161.             cy = CY ;
  162.             dx = DX ;
  163.             dy = DY ;
  164.  
  165.             // This one has 'everything' (i.e. a sys menu, min/max buttons,
  166.             // and a thick frame).
  167.             //
  168.             // It has a horizontal caption.
  169.             //
  170.             hwnd1 = CreateWindow( 
  171.                                     "ItsyWnd",
  172.                                     "ItsyBits #1",
  173.                                     IBS_HORZCAPTION |
  174.                                     WS_MAXIMIZEBOX |
  175.                                     WS_MINIMIZEBOX |
  176.                                     WS_SYSMENU|
  177.                                     WS_THICKFRAME |
  178.                                     WS_BORDER |
  179.                                     WS_POPUP,
  180.                                     cx,
  181.                                     cy,
  182.                                     dx,
  183.                                     dy ,
  184.                                     hWnd,
  185.                                     NULL,
  186.                                     hinstApp,
  187.                                     NULL ) ;
  188.  
  189.             // Create an ItsyBits window with a sys menu, min button, and
  190.             // a standard border (non-sizable).
  191.             //
  192.             // It has a horizontal caption.
  193.             //
  194.             hwnd2 = CreateWindow(
  195.                                     "ItsyWnd",
  196.                                     "ItsyBits #2",
  197.                                     IBS_HORZCAPTION |
  198.                                     WS_MINIMIZEBOX |
  199.                                     WS_SYSMENU|
  200.                                     WS_BORDER |
  201.                                     WS_POPUP,
  202.                                     cx += dx + 10, 
  203.                                     cy, 
  204.                                     dx,
  205.                                     dy,
  206.                                     hWnd,
  207.                                     NULL,
  208.                                     hinstApp,
  209.                                     NULL ) ;
  210.         
  211.             // Create the most boring ItsyBits window possible (no sys   
  212.             // menu, no min/max, and a non-sizable border.)
  213.             //
  214.             // It has a tiny horizontal caption.
  215.             //
  216.             hwnd3 = CreateWindow(
  217.                                     "ItsyWnd",
  218.                                     "",
  219.                                     IBS_HORZCAPTION |
  220.                                     WS_SYSMENU|
  221.                                     WS_BORDER |
  222.                                     WS_POPUP,
  223.                                     cx += dx + 10, 
  224.                                     cy, 
  225.                                     dx,
  226.                                     dy,
  227.                                     hWnd,
  228.                                     NULL,
  229.                                     hinstApp,
  230.                                     NULL ) ;
  231.             ibSetCaptionSize( hwnd3, ibGetCaptionSize( hwnd3 ) - 3 ) ;
  232.  
  233.             // This is the last of the horizontal caption ones.  It
  234.             // is just like ItsyBits #1 but has a caption that's a bit
  235.             // larger. 
  236.             //
  237.             // It has a horizontal caption.
  238.             //
  239.             hwnd4 = CreateWindow(
  240.                                     "ItsyWnd",
  241.                                     "ItsyBits #4 (No Parent)",
  242.                                     IBS_HORZCAPTION |
  243.                                     WS_MAXIMIZEBOX |
  244.                                     WS_MINIMIZEBOX |
  245.                                     WS_SYSMENU|
  246.                                     WS_THICKFRAME |
  247.                                     WS_BORDER |
  248.                                     WS_POPUP,
  249.                                     cx += dx + 10, 
  250.                                     cy, 
  251.                                     dx * 2,
  252.                                     dy,
  253.                                     NULL, // No parent 'cause it has a min button
  254.                                     NULL,
  255.                                     hinstApp,
  256.                                     NULL ) ;
  257.             ibSetCaptionSize( hwnd4, ibGetCaptionSize( hwnd4 ) + 4 ) ;
  258.  
  259.  
  260.             // Create a vertical captioned ItsyBits window.  
  261.             // This one has 'everything' (i.e. a sys menu, min/max buttons,
  262.             // and a thick frame).
  263.             //
  264.             hwnd5 = CreateWindow( 
  265.                                     "ItsyWnd",
  266.                                     "ItsyBits #5",
  267.                                     IBS_VERTCAPTION |
  268.                                     WS_MAXIMIZEBOX |
  269.                                     WS_MINIMIZEBOX |
  270.                                     WS_SYSMENU|
  271.                                     WS_THICKFRAME |
  272.                                     WS_BORDER |
  273.                                     WS_POPUP,
  274.                                     CX,
  275.                                     cy += dy + 10,
  276.                                     DY,
  277.                                     DX,
  278.                                     hWnd,
  279.                                     NULL,
  280.                                     hinstApp,
  281.                                     NULL ) ;
  282.             ibSetCaptionSize( hwnd5, ibGetCaptionSize( hwnd5 ) + 3 ) ;
  283.  
  284.             // Create a vertical captioned ItsyBits window.  
  285.             // Make this one have only a system menu.
  286.             //
  287.             // This one's vertical caption is the same widht as
  288.             // the standard Windows' captions are high.
  289.             //
  290.             hwnd6 = CreateWindow( 
  291.                                     "ItsyWnd",
  292.                                     "ItsyBits #6",
  293.                                     IBS_VERTCAPTION |
  294.                                     WS_SYSMENU|
  295.                                     WS_BORDER |
  296.                                     WS_POPUP,
  297.                                     CX,
  298.                                     cy + DX + 10,
  299.                                     DY,
  300.                                     DX,
  301.                                     hWnd,
  302.                                     NULL,
  303.                                     hinstApp,
  304.                                     NULL ) ;
  305.             ibSetCaptionSize( hwnd6, GetSystemMetrics( SM_CYCAPTION ) ) ;
  306.         }
  307.         break ;
  308.  
  309.         case WM_DESTROY:
  310.             if (hwnd1 && IsWindow( hwnd1 ))
  311.                 DestroyWindow( hwnd1 ) ;
  312.  
  313.             if (hwnd2 && IsWindow( hwnd2 ))
  314.                 DestroyWindow( hwnd2 ) ;
  315.  
  316.             if (hwnd3 && IsWindow( hwnd3 ))
  317.                 DestroyWindow( hwnd4 ) ;
  318.  
  319.             if (hwnd4 && IsWindow( hwnd4 ))
  320.                 DestroyWindow( hwnd4 ) ;
  321.  
  322.             if (hwnd5 && IsWindow( hwnd5 ))
  323.                 DestroyWindow( hwnd5 ) ;
  324.  
  325.             if (hwnd5 && IsWindow( hwnd5 ))
  326.                 DestroyWindow( hwnd5 ) ;
  327.  
  328.             PostQuitMessage( 0 ) ;
  329.         break ;
  330.  
  331.         default:
  332.             return DefWindowProc( hWnd, uiMsg, wParam, lParam ) ;
  333.     }
  334.  
  335.     return 0L ;
  336.  
  337. } // fnMainWnd() ///
  338.  
  339.  
  340. ////////////////////////////////////////////////////////////////
  341. //  int PASCAL
  342. //     WinMain( HANDLE hinst, HANDLE hinstPrev, LPSTR lpszCmd, in nCmdShow )
  343. //
  344. //  Description: 
  345. //
  346. //
  347. //
  348. //  Comments:
  349. //
  350. ////////////////////////////////////////////////////////////////
  351. int PASCAL WinMain( HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpszCmd, int nCmdShow )
  352. {
  353.     int     n ;
  354.     MSG     msg ;
  355.  
  356.     hinstApp = hinst ;
  357.  
  358.     if (!hinstPrev)
  359.         if (!InitClass( hinst ))
  360.         {
  361.             goto HellInAHandBasket2 ;
  362.         }
  363.  
  364.     // Read defaults
  365.     //
  366.     if (!(hwndApp = CreateMain()))
  367.     {
  368.         goto HellInAHandBasket2 ;
  369.     }
  370.  
  371.     ShowWindow( hwndApp, nCmdShow ) ;
  372.     UpdateWindow( hwndApp ) ;
  373.  
  374.     // Make all of the itsybits windows visible.
  375.     //
  376.     ShowWindow( hwnd1, SW_SHOWNORMAL ) ;
  377.     UpdateWindow( hwnd1 ) ;
  378.  
  379.     ShowWindow( hwnd2, SW_SHOWNORMAL ) ;
  380.     UpdateWindow( hwnd2 ) ;
  381.  
  382.     ShowWindow( hwnd3, SW_SHOWNORMAL ) ;
  383.     UpdateWindow( hwnd3 ) ;
  384.  
  385.     ShowWindow( hwnd4, SW_SHOWNORMAL ) ;
  386.     UpdateWindow( hwnd4 ) ;
  387.  
  388.     ShowWindow( hwnd5, SW_SHOWNORMAL ) ;
  389.     UpdateWindow( hwnd5 ) ;
  390.  
  391.     ShowWindow( hwnd6, SW_SHOWNORMAL ) ;
  392.     UpdateWindow( hwnd6 ) ;
  393.  
  394.     SetActiveWindow( hwnd4 ) ;
  395.  
  396.     while (GetMessage (&msg, NULL, 0, 0))
  397.     {
  398.         TranslateMessage( &msg ) ;
  399.         DispatchMessage( &msg ) ;
  400.     }
  401.  
  402.     return (int)msg.wParam ;
  403.  
  404. HellInAHandBasket2:
  405.                                 
  406.     return n ;
  407.  
  408. } // MyWinMain() ///
  409.  
  410.  
  411. ////////////////////////////////////////////////////////////////
  412. //  BOOL WINAPI InitClass( HINSTANCE hInstance )
  413. //
  414. //  Description: 
  415. //
  416. //     Registers the window classes.
  417. //
  418. //  Comments:
  419. //
  420. ////////////////////////////////////////////////////////////////
  421. BOOL WINAPI InitClass( HINSTANCE hInstance )
  422. {
  423.     WNDCLASS    wc ;
  424.     BOOL        f = TRUE ;
  425.  
  426.     wc.style            = 0L ;
  427.     wc.lpfnWndProc      = fnMainWnd ;
  428.     wc.cbClsExtra       = 0 ;
  429.     wc.cbWndExtra       = 0 ;
  430.     wc.hInstance        = hInstance ;
  431.     wc.hIcon            = LoadIcon( hInstance, "IDI_ITSYTEST" ) ;
  432.     wc.hCursor          = LoadCursor( NULL, IDC_ARROW ) ;
  433.     wc.hbrBackground    = (HBRUSH)(COLOR_APPWORKSPACE + 1) ;
  434.     wc.lpszMenuName     = NULL ;
  435.     wc.lpszClassName    = "ItsyTest" ;
  436.  
  437.     if (!RegisterClass( &wc ))
  438.         return FALSE ;
  439.  
  440.     wc.style            = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW ;
  441.     wc.lpfnWndProc      = fnItsyWnd;  
  442.     wc.hIcon            = LoadIcon( hInstance, "IDI_ITSYTEST" ) ;
  443.     wc.hbrBackground    = (HBRUSH)(COLOR_WINDOW + 1) ;
  444.     wc.lpszClassName    = "ItsyWnd";
  445.  
  446.     // Register the window class and return success/failure code.///
  447.  
  448.     return RegisterClass( &wc ) ;
  449.  
  450. } // InitClass() ///
  451.  
  452.  
  453. ////////////////////////////////////////////////////////////////
  454. //  HWND WINAPI CreateMain( VOID )
  455. //
  456. //  Description: 
  457. //
  458. //
  459. //
  460. //  Comments:
  461. //
  462. ////////////////////////////////////////////////////////////////
  463. HWND WINAPI CreateMain( VOID )
  464. {
  465.     HWND hwnd ;
  466.  
  467. #ifdef WIN32
  468.     hwnd = CreateWindow
  469.         (
  470.             "ItsyTest",
  471.             "ItsyBits Test Application (32 bits)",
  472.             WS_OVERLAPPEDWINDOW |
  473.             WS_CLIPCHILDREN,  
  474.             5,
  475.             5,
  476.             GetSystemMetrics( SM_CXFULLSCREEN ) - 10,
  477.             GetSystemMetrics( SM_CYCAPTION ) * 4,
  478.             NULL,                      
  479.             NULL,                      
  480.             hinstApp,                
  481.             NULL                        
  482.         ) ;
  483. #else
  484.     hwnd = CreateWindow
  485.         (
  486.             "ItsyTest",
  487.             "ItsyBits Test Application (16 bits)",
  488.             WS_OVERLAPPEDWINDOW |
  489.             WS_CLIPCHILDREN,  
  490.             5,
  491.             5,
  492.             GetSystemMetrics( SM_CXFULLSCREEN ) - 10,
  493.             GetSystemMetrics( SM_CYCAPTION ) * 4,
  494.             NULL,                      
  495.             NULL,                      
  496.             hinstApp,                
  497.             NULL                        
  498.         ) ;
  499. #endif
  500.  
  501.     return hwnd ;
  502.  
  503. } // CreateMain() ///
  504.  
  505.  
  506. ////////////////////////////////////////////////////////////////////////
  507. // End of File: ITSYTEST.c
  508. ////////////////////////////////////////////////////////////////////////
  509.  
  510.